﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Geometry;

namespace RobotRace.Geometry
{
    public class GeometryUtils
    {
        public static double sqr(double a)
        {
            return a * a;
        }

        public static Point translatePointFromRealToPaintCoordinates(RectangleF baseArea, Point2D point, Point lowerRightCorner)
        {
            float width = baseArea.Width;
            float height = baseArea.Height;

            float newWidth = lowerRightCorner.X;
            float newHeight = lowerRightCorner.Y;

            float xScale = width / newWidth;
            float yScale = height / newHeight;

            float newX = ((float)point.x - baseArea.X) / xScale;
            float newY = ((float)point.y - baseArea.Y) / yScale;

            return new Point((int)newX, (int)newY);
        }


        public static Point2D translatePointFromPaintToRealCoordinates(RectangleF baseArea, Point point, Point lowerRightCorner)
        {
            float width = lowerRightCorner.X;
            float height = lowerRightCorner.Y;

            float newWidth = baseArea.Width;
            float newHeight = baseArea.Height;

            float xScale = width / newWidth;
            float yScale = height / newHeight;

            float newX = ((float)point.X) / xScale + baseArea.X;
            float newY = ((float)point.Y) / yScale + baseArea.Y;

            return new Point2D(newX, newY);
        }
    }
}
